package lab02.Test11;

/**
 * Created by lenovo on 2017/10/24.
 */
public class Rectangle implements Printx {
    double a,b;
    Rectangle(double a,double b){
        this.a=a;
        this.b=b;
    }
    public double getArea(){
        return a*b;
    }
    public double getLength(){
        return (a+b)*2.0;
    }
    public void printMyWay(){
        System.out.println("矩形的长a="+a+" 宽b="+b);
        System.out.println("其面积S="+getArea());
        System.out.println("其周长L="+getLength());
    }
}
 class Square extends Rectangle{    //正方形类Square
    double c;
    Square(double a,double b){
        super(a,b);
    }
    public double getDiagonal(){    //求对角线长度
        c=Math.sqrt(a*a+b*b);
        return c;
    }
    public void printMyWay(){
        System.out.println("正方形的边长a=b="+a);
        System.out.println("其面积S="+getArea());
        System.out.println("其周长L="+getLength());
        System.out.println("其对角线c="+getDiagonal());
    }
}

